import java.util.Stack;

class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }
    
    public void push(int x) {
        s1.push(x);//入队列时将元素入到第一个栈
    }
    
    public int pop() {
        if(!s2.empty()){
           return s2.pop();//出队列将元素出到第二个栈
        }else{
            while(!s1.empty()){
                int val = s1.pop();
                s2.push(val);
            }
        }
        return s2.pop();
    }
    
    public int peek() {
        if(!s2.empty()){
            return s2.peek();
        }else{
            while(!s1.empty()){
                int val = s1.pop();
                s2.push(val);
            }
        }
        return s2.peek();
    }
    
    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */